package cn.ratel.aop;

import cn.ratel.kit.CollectionKit;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class EnhancerCallback implements MethodInterceptor {

	@Override
	public Object intercept(Object target, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
		if (CollectionKit.isEmpty(ProxyKit.getEnhancers(method))) {
			return methodProxy.invokeSuper(target, args);
		}
		MethodInvocation invocation = new MethodInvocation(target, method, args, methodProxy);
		invocation.invoke();
		return invocation.getReturnValue();
	}
}
